import random
import json

# 声母列表
initials = ['b', 'p', 'm', 'f', 'd', 't', 'n', 'l', 'g', 'k', 'h',
            'j', 'q', 'x', 'zh', 'ch', 'sh', 'r', 'z', 'c', 's', 'y', 'w']

# 韵母列表
finals = ['a', 'o', 'e', 'i', 'u', 'ü', 'ai', 'ei', 'ui', 'ao', 'ou', 'iu',
          'ie', 'üe', 'er', 'an', 'en', 'in', 'un', 'ün', 'ang', 'eng', 'ing', 'ong']

# 随机选取一个声母和一个韵母
random_initial = random.choice(initials)
random_final = random.choice(finals)

# 组合成拼音
pinyin = random_initial + random_final

# 加载汉字拼音字典
with open('pinyin_to_chinese.json', encoding='utf-8') as f:
    pinyin_dict = json.load(f)

# 查找拼音对应的汉字
characters = pinyin_dict.get(pinyin, [])

print(f"随机生成的拼音是：{pinyin}")
print(f"对应的汉字有：{', '.join(characters)}")
